package com.jzr.bedside.ui.skill

import android.view.View
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.jzr.bedside.R
import com.jzr.bedside.base.BaseActivity
import com.jzr.bedside.base.BaseFragmentPageAdapter
import com.jzr.bedside.base.Constant
import com.jzr.bedside.bean.HospitalDetailsBean
import com.jzr.bedside.ui.adapter.HospitalDetailsLeftAdapter
import com.jzr.bedside.ui.fragment.hospital.*
import kotlinx.android.synthetic.main.actionbar_root_layout.*
import kotlinx.android.synthetic.main.activity_hospital_details.*
import java.util.ArrayList

class HospitalDetailsActivity : BaseActivity(), View.OnClickListener,
    HospitalDetailsLeftAdapter.onListItemClick {


    private var adapter: HospitalDetailsLeftAdapter? = null
    private val mFragments = ArrayList<Fragment>()
    private var mAdapter: BaseFragmentPageAdapter? = null
    private var listHospitalDetails = mutableListOf<HospitalDetailsBean>()

    override fun getLayoutId(): Int {
        return R.layout.activity_hospital_details
    }

    override fun attachView() {

    }

    override fun detachView() {

    }

    override fun initView() {
        ivRight.setOnClickListener(this)

        for ((index, item) in Constant.hospitalTitle.withIndex()) {
            val hospitalDetailsBean = HospitalDetailsBean()
            hospitalDetailsBean.id = index
            hospitalDetailsBean.title = Constant.hospitalTitle[index]
            listHospitalDetails.add(hospitalDetailsBean)
        }

        mFragments.add(HospitaDetailsFragment.getInstance()!!)
        mFragments.add(DeptDetailsFragment.getInstance()!!)
        mFragments.add(HospitaLeaderFragment.getInstance()!!)
        mFragments.add(HospitaMilieuFragment.getInstance()!!)
        mFragments.add(HospitaDeviceFragment.getInstance()!!)
        mFragments.add(HospitaCultureFragment.getInstance()!!)
        mFragments.add(HospitaContactusFragment.getInstance()!!)
        mFragments.add(HospitaMailBoxFragment.getInstance()!!)
        mAdapter = BaseFragmentPageAdapter(
            supportFragmentManager,
            mFragments,
            null
        )
        vpTab.adapter = mAdapter
        vpTab.currentItem = 0

        adapter = HospitalDetailsLeftAdapter(listHospitalDetails)
        adapter?.onListItemClick(this)
        rvTab.adapter = adapter
        val manager = LinearLayoutManager(this)
        manager.orientation = LinearLayoutManager.VERTICAL
        rvTab.layoutManager = manager

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.ivRight -> {
                finish()
            }
        }
    }

    override fun onListItemClick(item: HospitalDetailsBean?) {
        if(item?.id!=null){
            vpTab.setCurrentItem(item.id,false)
        }
    }

}
